/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.netcracker.test.ten;

import java.io.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author I
 */
public class Serializing {
    
  public void serialize(Person person){
        FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        try {
            fos = new FileOutputStream("temp.out");
            oos = new ObjectOutputStream(fos);
            
            oos.writeObject(person);
            oos.flush();
            oos.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
        }
          catch (IOException ex) {
              Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fos.close();
                oos.close();
            } catch (IOException ex) {
                Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
  }
  public Person deserialize(){
        FileInputStream fis = null;
        ObjectInputStream oin = null;
        Person person = null;
        
        try {
            fis = new FileInputStream("temp.out");  
            oin = new ObjectInputStream(fis);
            try {
                person = (Person) oin.readObject();
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
        } 
        catch (IOException ex) {
                Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
        }finally {
            try {
                fis.close();
                oin.close();
            } catch (IOException ex) {
                Logger.getLogger(Serializing.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return person;
  }
}
